﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using RM2012Service.DataService;
using RM2012Service.Business;
using System.Data.SqlClient;
using System.Data;

namespace RM2012Service.DataAccess
{
    public class PermissionDAO
    {
        DBConnection db;

        public PermissionDAO()
        {
            db = new DBConnection();
        }

        public DataTable GetAllPermission()
        {
            return db.ExecuteDataTable("GetAllPermission", null);
        }

        public int AddPermission(PermissionInfo info)
        {
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@UserId", SqlDbType.VarChar, 6);
            param[0].Value = info.UserId;

            param[1] = new SqlParameter("@UserGroupId", SqlDbType.VarChar, 4);
            param[1].Value = info.UserGroupId;

            return db.ExecuteNoneQuery("AddPermission", param);
        }

        public int UpdatePermission(PermissionInfo info)
        {
            SqlParameter[] param = new SqlParameter[2];
            param[0] = new SqlParameter("@UserId", SqlDbType.VarChar, 6);
            param[0].Value = info.UserId;

            param[1] = new SqlParameter("@UserGroupId", SqlDbType.VarChar, 4);
            param[1].Value = info.UserGroupId;

            return db.ExecuteNoneQuery("UpdatePermission", param);
        }

        public int DeletePermissionByUserId(string userId)
        {
            SqlParameter param = new SqlParameter("@UserId", SqlDbType.VarChar, 6);
            param.Value = userId;

            return db.ExecuteNoneQuery("DeletePermissionByUserId", param);
        }

        public int DeletePermissionByUserGroupId(string userGroupId)
        {
            SqlParameter param = new SqlParameter("@UserGroupId", SqlDbType.VarChar, 4);
            param.Value = userGroupId;

            return db.ExecuteNoneQuery("DeletePermissionByUserGroupId", param);
        }
    }
}
